package com.yeyks.mattress.controller;


import com.yeyks.common.ajax.AjaxResponseBody;
import com.yeyks.commonReference.service.mattress.MattressApiService;
import com.yeyks.commonReference.service.mattress.OrderInfoMattressService;
import com.yeyks.commonReference.utils.UserUtils;
import com.yeyks.consumer.dal.domain.UserInfo;
import com.yeyks.mattress.param.*;
import com.yeyks.mattress.service.MattressPackageConfigService;
import com.yeyks.mattress.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 共享床垫
 * </p>
 *
 * @author yun
 * @since 2019-07-16
 */
@Api(tags = "共享床垫", description = "共享床垫")
@RestController
@RequestMapping("/mattress/info")
public class MattressController {

    @Autowired
    private MattressPackageConfigService mattressPackageConfigService;
    @Autowired
    private OrderInfoMattressService orderInfoMattressService;
    @Autowired
    private MattressApiService mattressApiService;

    @ApiOperation(value = "查询床垫套餐信息:v1.0.0")
    @RequestMapping(value = "/packageList", method = {RequestMethod.GET})
    public AjaxResponseBody<OrderInfoMattressPackageListVo> packageList() {
        UserUtils.getLoginUser();
        OrderInfoMattressPackageListVo listVo = mattressPackageConfigService.packageList();
        return AjaxResponseBody.success(listVo);
    }

    @ApiOperation(value = "床垫状态:v1.0.0")
    @RequestMapping(value = "/mattressStatus", method = {RequestMethod.POST})
    public AjaxResponseBody<OrderInfoMattressMattressStatusVo> mattressStatus(@Validated OrderInfoMattressMattressStatusParam param) {
        UserInfo loginUser = UserUtils.getLoginUser();
        param.setUserId(loginUser.getId());
        OrderInfoMattressMattressStatusVo orderInfoMattressMattressStatusVo = mattressApiService.mattressStatus(param);
        return AjaxResponseBody.success(orderInfoMattressMattressStatusVo);
    }

    @ApiOperation(value = "下单:v1.0.0")
    @RequestMapping(value = "/placeAnOrder", method = {RequestMethod.POST})
    public AjaxResponseBody<OrderInfoMattressPlaceAnOrderVo> placeAnOrder(@Validated OrderInfoMattressPlaceAnOrderParam param) {
        UserInfo loginUser = UserUtils.getLoginUser();
        param.setUserId(loginUser.getId());
        param.setUserPhone(loginUser.getPhone());
        OrderInfoMattressPlaceAnOrderVo orderInfoMattressPlaceAnOrderVo = orderInfoMattressService.placeAnOrder(param);
        return AjaxResponseBody.success(orderInfoMattressPlaceAnOrderVo);
    }

    @ApiOperation(value = "订单信息:v1.0.0")
    @RequestMapping(value = "/orderList", method = {RequestMethod.POST})
    public AjaxResponseBody<OrderInfoMattressOrderListVo> orderList(OrderInfoMattressOrderListParam param) {
        UserInfo loginUser = UserUtils.getLoginUser();
        param.setUserId(loginUser.getId());
        OrderInfoMattressOrderListVo orderInfoMattressPageInfo = orderInfoMattressService.orderList(param);
        return AjaxResponseBody.success(orderInfoMattressPageInfo);
    }

    @ApiOperation(value = "查询床垫是否启动成功:v1.0.1")
    @RequestMapping(value = "/checkMattressStartSuccess", method = {RequestMethod.POST})
    public AjaxResponseBody<CheckMattressStartSuccessVo> checkMattressStartSuccess(@Validated CheckMattressStartSuccessParam param) {
        return AjaxResponseBody.success(orderInfoMattressService.checkMattressStartSuccess(param));
    }

    @ApiOperation(value = "订单支付失败:v1.0.0")
    @RequestMapping(value = "/orderPayFail", method = {RequestMethod.POST})
    public AjaxResponseBody<OrderInfoMattressOrderPayFailVo> orderPayFail(@Validated OrderInfoMattressOrderPayFailParam param) {
        UserInfo loginUser = UserUtils.getLoginUser();
        param.setUserId(loginUser.getId());
        OrderInfoMattressOrderPayFailVo orderInfoMattressOrderPayFailVo = orderInfoMattressService.orderPayFail(param);
        return AjaxResponseBody.success(orderInfoMattressOrderPayFailVo);
    }

}
